import * as productApi from '../../utils/product.api.js'
Page({
  data: {
    banners: [
      {
        id: 1,
        imageUrl: 'https://knowage2025.oss-cn-hangzhou.aliyuncs.com/uploads/banner1.png'
      },
      {
        id: 2,
        imageUrl: 'https://knowage2025.oss-cn-hangzhou.aliyuncs.com/uploads/banner2.png'
      }
    ],
    categories: [],
    recommendCourses: [
      
    ]
  },

  onLoad() {
    // TODO: 从服务器获取首页数据
    this.loadPageData()
  },

  async loadPageData() {
    // TODO: 实现数据加载逻辑
    const res = await productApi.getCategoryList()
    // 获取产品列表
    const res2 = await productApi.getProductList({
      
    })
    this.setData({
      categories: res.data,
      recommendCourses: res2.data.rows
    })
  },

  onBannerTap(e) {
    const id = e.currentTarget.dataset.id
    // TODO: 跳转到轮播图对应的页面
  },

  onCategoryTap(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/course/list?categoryId=${id}`
    })
  },

  onCourseTap(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/course/detail?id=${id}`
    })
  },

  onMoreTap() {
    wx.switchTab({
      url: '/pages/course/list'
    })
  }
})